package com.my.test.design.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserServiceProxy implements InvocationHandler {

    // 被代理对象
    private Object obj;

    // 返回一个代理对象
    public Object bind (Object obj){
        this.obj = obj;
        return Proxy.newProxyInstance(obj.getClass().getClassLoader(),
                obj.getClass().getInterfaces(),this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("begin 开始执行方法");
        Object object = method.invoke(obj,args);
        System.out.println("end 执行方法结束");
        return object;
    }
}
